<?php
include_once("../module/sns/config.php");
if($_POST['act']=="ajax_get_paster"){
	//已经绑定的贴纸ID
	$sql = "select paster_id from ".SNSTAGS." where status=1 and paster_id>0 group by paster_id";
	$db->query($sql);
	$pasteridarr = $db->getRows();
	$pasterids = array(0);
	foreach ($pasteridarr as $pv)
	{
		$pasterids[] = $pv['paster_id'];
	}
	
	$where = "";
	if($_POST['name']!=""){
		$where = " and name like '%$_POST[name]%'";
	}
	$where .=" and id not in(".implode(",", $pasterids).")";//排除已绑定的贴纸
	$sql = "select * from ".SNSPASTER." where status=1 ".$where." order by displayorder,create_time desc";
	$db->query($sql);
	$res = $db->getRows();
	$return = "";
	foreach ($res as $val)
	{
		$return .= "<div><a href='javascript:void(0);' onclick='choose_paster(".$val['id'].",\"$val[name]\");' class='menuas'><img style='float: left;' src='".$val['pic']."' width='80' height='80'/><span style='height:80px;line-height: 80px;'>".$val['name']."</span></a></div><br />";
	}
	echo $return;exit;
}
if($_GET['act']=="op"){
	if(!empty($_GET['chk'])){
		$pasterids = "";
		foreach ($_GET['chk'] as $pasterid)
		{
			$pasterids .= $pasterid.",";
		}
		if($pasterids!=""){
			if($_GET['set_status']!=""){
				$sql = "update ".SNSPASTER." set status='".$_GET['set_status']."' where id IN (".rtrim($pasterids,",").")";
				$db->query($sql);
				msg('?m=sns&s=sns_paster.php');
			}
		}
	}
}else{
	$where = "";
	$timeorder = "desc";
	if($_GET['status']!=""){
		$where .=" and status='$_GET[status]'";
	}
	
	if($_GET['timeorder']=='asc'){
		$timeorder = "asc";
	}

    $sql = "select * from ".SNSPASTER." where 1 ".$where." order by displayorder,create_time ".$timeorder;
    $db->query($sql);
    include_once("../includes/page_utf_class.php");
    $page = new Page;
    $page->listRows=20;
    $db->query($sql);
    $totalRows = $db->num_rows();
    if (!$page->__get('totalRows')){
        $db->query($sql);
        $page->totalRows = $db->num_rows();
    }
    $sql .= "  limit ".$page->firstRow.",".$page->listRows;
    
    $db->query($sql);
    $de['page'] = $page->prompt();
    $de['list']=$db->getRows();
}

$tpl->assign('countpro',$totalRows);
$tpl->assign('de',$de);
$tpl->assign('img_url_pre',$img_url_pre);
$tpl->display('sns_paster.htm');
?>